﻿namespace NEvoWeb.Modules.NB_Store
{
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Collections;

    public class RelatedProducts
    {
        public static void AddProduct(int PortalID, string ProductID, string RelatedProductID)
        {
            ProductController controller = new ProductController();
            NB_Store_ProductRelatedInfo objInfo = new NB_Store_ProductRelatedInfo {
                RelatedID = -1,
                PortalID = PortalID,
                ProductID = Conversions.ToInteger(ProductID),
                RelatedProductID = Conversions.ToInteger(RelatedProductID),
                RelatedType = 1,
                BiDirectional = true,
                Disabled = false,
                DiscountAmt = decimal.Zero,
                DiscountPercent = decimal.Zero,
                MaxQty = 0,
                NotAvailable = false,
                ProductQty = 0
            };
            controller.UpdateObjProductRelated(objInfo);
        }

        public static void AddProductFromWishList(int PortalID, string ProductID)
        {
            IEnumerator enumerator=null;
            ProductController controller = new ProductController();
            ArrayList list = WishList.GetList(PortalID);
            try
            {
                enumerator = list.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    ProductListInfo current = (ProductListInfo) enumerator.Current;
                    AddProduct(PortalID, ProductID, Conversions.ToString(current.ProductID));
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            WishList.ClearList(PortalID);
        }
    }
}

